//
//  HRInfoModel.m
//  Btpin
//
//  Created by Vic on 2019/3/21.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "HRInfoModel.h"

@implementation HRInfoModel

- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
    self.userid = [UIToolsControl dataAnalysis:keyedValues[@"userid"]];
    self.name = [UIToolsControl dataAnalysis:keyedValues[@"name"]];
    self.avatar = [UIToolsControl dataAnalysis:keyedValues[@"avatar"]];
    self.position = [UIToolsControl dataAnalysis:keyedValues[@"position"]];
    self.last_time = [UIToolsControl dataAnalysis:keyedValues[@"last_time"]];
    self.last_timeShow = @"刚刚";
    if (self.last_time && self.last_time.length) {
        long minute = 60 * 1000; // 1分
        long hour = 60 * minute; // 1小时
        long day = 24 * hour; // 1天
        long month = 31 * day; // 1月
        long year = 12 * month; // 1年
        
        long diff = [[UIToolsControl getCurrentTimestamp] integerValue] - [self.last_time integerValue];
        NSInteger r = 0;
        if (diff > year) {
            r = (diff / year);
            self.last_timeShow = [NSString stringWithFormat:@"%ld年前", (long)r];
        } else if (diff > month) {
            r = (diff / month);
            self.last_timeShow = [NSString stringWithFormat:@"%ld个月前", (long)r];
        } else if (diff > day) {
            r = (diff / day);
            self.last_timeShow = [NSString stringWithFormat:@"%ld天前", (long)r];
        } else if (diff > hour) {
            r = (diff / hour);
            self.last_timeShow = [NSString stringWithFormat:@"%ld个小时前", (long)r];
        } else if (diff > minute) {
            r = (diff / minute);
            self.last_timeShow = [NSString stringWithFormat:@"%ld分钟前", (long)r];
        } else {
            self.last_timeShow = @"刚刚";
        }
    }
    
    self.realname_audit = [UIToolsControl dataAnalysis:keyedValues[@"realname_audit"]];
    self.nickname = [UIToolsControl dataAnalysis:keyedValues[@"nickname"]];
    self.avatar = [UIToolsControl dataAnalysis:keyedValues[@"avatar"]];
    self.department = [UIToolsControl dataAnalysis:keyedValues[@"department"]];
    self.mobile = [UIToolsControl dataAnalysis:keyedValues[@"mobile"]];
    self.email = [UIToolsControl dataAnalysis:keyedValues[@"email"]];
    self.weixin = [UIToolsControl dataAnalysis:keyedValues[@"weixin"]];
    self.weixin_img = [UIToolsControl dataAnalysis:keyedValues[@"weixin_img"]];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)copyWithZone:(NSZone *)zone {
    HRInfoModel *model = [[[self class] allocWithZone:zone] init];
    model.userid = self.userid;
    model.name = self.name;
    model.avatar = self.avatar;
    model.position = self.position;
    
    model.realname_audit = self.realname_audit;
    model.nickname = self.nickname;
    model.department = self.department;
    model.mobile = self.mobile;
    model.email = self.email;
    model.weixin = self.weixin;
    model.weixin_img = self.weixin_img;
    
    return model;
}

@end
